import { storeToRefs } from 'pinia'
import { useGlobalStore } from '@/stores/modules/global'
import { localSet } from '@/utils'

/**
 * @description 全局主题 hooks
 * */
export const useTheme = () => {
  const globalStore = useGlobalStore()
  const { isDark } = storeToRefs(globalStore)

  // 切换暗黑模式 ==> 同时修改主题颜色、侧边栏、头部颜色
  const switchDark = () => {
    const html = document.documentElement as HTMLElement
    isDark.value ? html.setAttribute('class', '') : html.setAttribute('class', 'dark')
    isDark.value = !isDark.value
    localSet('app-dark', isDark.value)
  }

  return {
    isDark,
    switchDark
  }
}
